<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.ort">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script th:src="@{/layui/layui.js}" type="text/javascript"></script>
    <link th:href="@{/layui/css/layui.css}" rel="stylesheet" />
    <style type="text/css">
        .layui-table-cell{
            height: auto;
            line-height: 50px;
        }
    </style>
</head>

<body>

<div class="layui-panel" style="padding: 8px;">
    <fieldset class="layui-elem-field layui-border-green">
        <legend>搜索信息</legend>
        <form class="layui-form layui-form-pane" style="margin: 20px;">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">品牌商Id</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" type="text" name="brandId" autocomplete="off" />

                    </div>
                    <label class="layui-form-label">品牌商名称</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" type="text" name="title" autocomplete="off" />

                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <a class="layui-btn layui-btn-primary" lay-submit="" lay-filter="searchBtn">
                            <i class="layui-icon layui-icon-search"></i>
                            搜索
                        </a>
                    </div>
                </div>
            </div>
        </form>
    </fieldset>
    <div class="layui-table-cell">
        <table id="brandTable" lay-filter="brandTable"></table>
    </div>
</div>

<script id="tool" type="text/html">
    <a class="layui-btn layui-btn-wram " lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger " lay-event="delete">删除</a>
</script>

<script id="tableBar" type="text/html">
    <a class="layui-btn layui-btn-wram layui-btn-md" lay-event="add">
        <i class="layui-icon layui-icon-add-1"></i>
        添加
    </a>
</script>

<script id="photo" type="text/html">
    <img src="/file/fc/showImg/{{d.photo}}" style="width: 70px;height: 49px;">
</script>

<script>

    var $;
    layui.use(['jquery','layer','table','form'],function(){
        var layer=layui.layer,
            table=layui.table,
            form=layui.form;
            $=layui.jquery;
        table.render({
            elem:'#brandTable',
            height:'full-70',
            page:true,
            toolbar:'#tableBar',
            url:'/brand/bc/find',
            cols:[
                [
                    {field:'brandId',title:'品牌商Id',width:160,align:'center'},
                    {field:'title',title:'品牌商名称',width:160,align:'center'},
                    {field:'photo',title:'品牌商图片',width:200,templet:'#photo',align:'center'},
                    {field:'introduce',title:'品牌介绍',align:'center'},
                    {field:'price',title:'底价',width:160,align:'center'},
                    {fixed:'right',title:'操作',width:180,toolbar:'#tool',align:'center'}
                ]
            ]
        })
        form.on('submit(searchBtn)',function(data){
            var dataForm = data.field;
            table.reload('brandTable',{
                page:{
                    curr:1
                },
                where: {
                   brandId:dataForm.brandId,
                   title: dataForm.title
                }
                })
            })
        var active={
            addOrUpdate:function (content){
                var b=false;
                top.layer.open({
                    type:2,
                    content:content,
                    area:['820px','775px'],
                    btn:['确认保存','取消关闭'],
                    btn1:function (i,o){
                        b=true;
                        o.find('iframe')[0].contentWindow.btnSubmit();
                    },
                    end:function (){
                        if (b) layui.table.reload('brandTable');
                    }
                })
            },
            deleteBrand:function (id) {
                layer.confirm('确实删除该记录吗？', function (index) {
                    if (index > 0) {
                        $.ajax({
                            type: 'post',
                            url: '/brand/bc/delete',
                            data: {
                                id: id
                            },
                            dataType: 'json',
                            success: function (result) {
                                layer.msg(result.msg);
                                if (result.is) {
                                    layui.table.reload('brandTable');
                                }
                            }
                        })
                    }
                    layer.close(index);
                })
            }
        }

        table.on('toolbar(brandTable)',function (obj){
            var event=obj.event;
            if("add"==event){
                active.addOrUpdate('/page/brand/brandAdd');
            }
        })
        table.on('tool(brandTable)',function (obj){
            var event=obj.event;
            if ("edit"==event){
                active.addOrUpdate('/brand/ud/editBrand/'+obj.data.id);
            }
            if ("delete"==event){
                active.deleteBrand(obj.data.id);
            }
        })
    })
</script>
</body>
</html>
